package com.example.warehouse.bus.controller;

import com.example.warehouse.bus.pojo.entity.BusCustomer;
import com.example.warehouse.bus.pojo.param.BusCustomerAddNewParam;
import com.example.warehouse.bus.pojo.vo.BusCustomerStandardVO;
import com.example.warehouse.bus.service.IBusCustomerService;
import com.example.warehouse.common.pojo.vo.PageData;
import com.example.warehouse.common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * @author Linger
 * @date 2023-07-03 16:48
 * @desciption: 基础板块公司管理控制层
 */
@Slf4j
@RequestMapping("/busCustomer")
@RestController
@Api(tags = "2.1 基础管理-公司管理")
public class BusCustomerController {
    @Autowired
    private IBusCustomerService busCustomerService;

    public BusCustomerController() {
        log.info("创建控制器对象:BusCustomerController");
    }

    @ApiOperation("添加公司")
    @ApiOperationSupport(order = 100)
   @PreAuthorize("hasAuthority('/busCustomer/add-new')")
    @PostMapping("/add-new")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerName", value = "公司名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "connectionPerson", value = "联系人姓名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "phone", value = "联系电话", required = true, dataType = "String"),
            @ApiImplicitParam(name = "zip", value = "邮政编码", dataType = "String"),
            @ApiImplicitParam(name = "telephone", value = "移动电话", dataType = "String"),
            @ApiImplicitParam(name = "address", value = "地址", dataType = "String"),
            @ApiImplicitParam(name = "bank", value = "开户行", dataType = "String"),
            @ApiImplicitParam(name = "account", value = "银行卡号", dataType = "String"),
            @ApiImplicitParam(name = "email", value = "邮箱", dataType = "String"),
            @ApiImplicitParam(name = "fax", value = "传真号", dataType = "String"),
            @ApiImplicitParam(name = "enable", value = "是否启用", dataType = "Integer")
    })
    public JsonResult addNewBusCustomer(@Valid BusCustomerAddNewParam busCustomerAddNewParam) {
        log.debug("开始处理【新增公司】的请求，参数：{}", busCustomerAddNewParam);
        busCustomerService.addNewBusCustomer(busCustomerAddNewParam);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/delete")
    @ApiOperation("根据ID删除公司")
    @ApiOperationSupport(order = 200)
   @PreAuthorize("hasAuthority('/busCustomer/delete')")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "公司ID", required = true, dataType = "long")
    })
    public JsonResult deleteBusCostomerById(@PathVariable Long id) {
        log.debug("开始处理【根据ID删除公司】的请求，参数：{}", id);
        busCustomerService.delete(id);
        return JsonResult.ok();
    }
    @GetMapping("/{id}/getById")
    @ApiOperation("根据ID查询公司")
    @ApiOperationSupport(order = 250)
   @PreAuthorize("hasAuthority('/busCustomer/getById')")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "公司ID", required = true, dataType = "long")
    })
    public JsonResult getBusCostomerById(@PathVariable Long id) {
        log.debug("开始处理【根据ID查询公司】的请求，参数：{}", id);
        busCustomerService.getStandardById(id);
        return JsonResult.ok(busCustomerService.getStandardById(id));
    }

    @PostMapping("/update")
    @ApiOperation("修改公司信息")
    @ApiOperationSupport(order = 300)
   @PreAuthorize("hasAuthority('/busCustomer/update')")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerName", value = "公司名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "connectionPerson", value = "联系人姓名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "phone", value = "联系电话", required = true, dataType = "String"),
            @ApiImplicitParam(name = "zip", value = "邮政编码", dataType = "String"),
            @ApiImplicitParam(name = "telephone", value = "移动电话", dataType = "String"),
            @ApiImplicitParam(name = "address", value = "地址", dataType = "String"),
            @ApiImplicitParam(name = "bank", value = "开户行", dataType = "String"),
            @ApiImplicitParam(name = "account", value = "银行卡号", dataType = "String"),
            @ApiImplicitParam(name = "email", value = "邮箱", dataType = "String"),
            @ApiImplicitParam(name = "fax", value = "传真号", dataType = "String"),
            @ApiImplicitParam(name = "enable", value = "是否启用", dataType = "String")
    })
    public JsonResult updateBusCostomerById( BusCustomer busCustomer) {
        log.debug("开始处理【修改公司信息】的请求，参数：{}", busCustomer);
        busCustomerService.update(busCustomer);
        return JsonResult.ok();
    }

    @PostMapping("/query-get")
    @ApiOperation("模糊查询公司信息")
    @ApiOperationSupport(order = 420)
   @PreAuthorize("hasAuthority('/busCustomer/query-get')")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerName", value = "公司名称", dataType = "String"),
            @ApiImplicitParam(name = "connectionPerson", value = "联系人姓名", dataType = "String"),
            @ApiImplicitParam(name = "phone", value = "联系电话", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", dataType = "long")
    })
    public JsonResult queryByKeyWord(Integer page, @Param("customerName") String customerName, @Param("connectionPerson")String connectionPerson,@Param("phone")String phone) {
        log.debug("开始处理【模糊查询公司信息】的请求，参数：{},{},{}", customerName, connectionPerson, phone);
        Integer pageNum = page == null ? 1 : page;
        PageData<BusCustomerStandardVO> result = busCustomerService.queryByKeyWord(page,customerName, connectionPerson, phone);
        System.out.println(result);
        return JsonResult.ok(result);
    }


    @GetMapping("/get-id")
    @ApiOperation("查询公司列表")
    @ApiOperationSupport(order = 421)
   @PreAuthorize("hasAuthority('/busCustomer/get-id')")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", dataType = "long")
    })
    public JsonResult list(Integer page) {
        log.debug("开始处理【查询公司列表】的请求，页码：{}", page);
        Integer pageNum = page == null ? 1 : page;
        PageData<BusCustomer> pageData = busCustomerService.list(pageNum);
        return JsonResult.ok(pageData);
    }
    @GetMapping("/get-idAsc")
    @ApiOperation("升序查询公司列表")
    @ApiOperationSupport(order = 422)
   @PreAuthorize("hasAuthority('/busCustomer/get-idAsc')")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", dataType = "long")
    })
    public JsonResult listAsc(Integer page) {
        log.debug("开始处理【查询公司列表】的请求，页码：{}", page);
        Integer pageNum = page == null ? 1 : page;
        PageData<BusCustomer> pageData = busCustomerService.listAsc(pageNum);
        return JsonResult.ok(pageData);
    }
    @GetMapping("/get-idDesc")
    @ApiOperation("降序查询公司列表")
    @ApiOperationSupport(order = 423)
   @PreAuthorize("hasAuthority('/busCustomer/get-idDesc')")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", dataType = "long")
    })
    public JsonResult listDesc(Integer page) {
        log.debug("开始处理【查询公司列表】的请求，页码：{}", page);
        Integer pageNum = page == null ? 1 : page;
        PageData<BusCustomer> pageData = busCustomerService.listDesc(pageNum);
        return JsonResult.ok(pageData);
    }

    @PostMapping("/ban/{id:[0-9]+}/enable")
    @PreAuthorize("hasAuthority('/busCustomer/ban/update')")
    @ApiOperation("启用公司")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "公司ID", required = true, dataType = "long")
    })
    public JsonResult setEnable(@PathVariable Long id) {
        log.debug("开始处理【启用公司】的请求，参数：{}", id);
        busCustomerService.setEnable(id);
        return JsonResult.ok();
    }

    @PostMapping("/ban/{id:[0-9]+}/disable")
    @PreAuthorize("hasAuthority('/busCustomer/noban/update')")
    @ApiOperation("禁用公司")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "公司ID", required = true, dataType = "long")
    })
    public JsonResult setDisable(@PathVariable Long id) {
        log.debug("开始处理【禁用公司】的请求，参数：{}", id);
        busCustomerService.setDisable(id);
        return JsonResult.ok();
    }


}
